#include "simulation.h"

Simulation::Simulation(unsigned int x_size, unsigned int y_size, unsigned int tile_size)
{
    xSize = x_size;
    ySize = y_size;
    
    cellGrid = new Cell*[xSize];
    for(unsigned int i=0 ; i<xSize ; i++)
	cellGrid[i] = new Cell[ySize];
}

bool Simulation::isCell(int coord_x, int coord_y)
{
    if(coord_x < 0 || coord_x > xSize || coord_y < 0 || coord_y > ySize)
	return false;
    
    return true;
}

unsigned int Simulation::neighbours(unsigned int coord_x, unsigned int coord_y)
{
    unsigned int n = 0;
    
    for(int x=-1 ; x<=1 ; x++)
    {
	for(int y=-1 ; y<=1 ; y++)
	{
	    if(isCell(coord_x+x, coord_y+y))
	    {
		if(cellGrid[coord_x+x][coord_y+y].isAlive())
		    n++;
	    }
	}
    }
    
    return n;
}